home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / qttestapplet / src / qttestapplet.java
Encoding:
Java Source  |  2000-09-28  |  2.5 KB  |  88 lines

  1. /*
  2.  * quicktime.app: Sample Code for Initial Seeding
  3.  *
  4.  * © 1997 Copyright, Apple Computer
  5.  * All rights reserved
  6.  */
  7.  
  8. import java.applet.Applet;
  9. import java.awt.*;
  10.  
  11. import quicktime.*;
  12. import quicktime.io.QTFile;
  13.  
  14. import quicktime.app.display.*;
  15. import quicktime.app.image.ImageDrawer;    // for exceptions
  16.  
  17. public class QTTestApplet extends Applet {    
  18.     private boolean initDone = false;
  19.     
  20.     public void init () {
  21.         try {
  22.             if (QTSession.isInitialized() == false)
  23.                 QTSession.open();
  24.             initDone = true;
  25.         } catch (NoClassDefFoundError er) {
  26.             add (new Label ("Can't Find QTJava classes"), "North");
  27.             add (new Label ("Check install and try again"), "South");
  28.         } catch (SecurityException se) {
  29.                 // this is thrown by MRJ trying to find QTSession class
  30.             add (new Label ("Can't Find QTJava classes"), "North");
  31.             add (new Label ("Check install and try again"), "South");
  32.         } catch (Exception e) {
  33.                 // do a dynamic test for QTException 
  34.                 //so the QTException class is not loaded unless
  35.                 // an unknown exception is thrown by the runtime
  36.             if (e instanceof ClassNotFoundException || e instanceof java.io.FileNotFoundException) {
  37.                 add (new Label ("Can't Find QTJava classes"), "North");
  38.                 add (new Label ("Check install and try again"), "South");
  39.             } else if (e instanceof QTException) {
  40.                 add (new Label ("Problem with QuickTime install"), "North");
  41.                 if (((QTException)e).errorCode() == -2093)
  42.                     add (new Label ("QuickTime must be installed"), "South");            
  43.                 else
  44.                     add (new Label (e.getMessage()), "South");            
  45.             }
  46.         }
  47.     }
  48.     
  49.     // we create an inner class here so that the class loader
  50.     // does NOT try to load QT classes until we know that 
  51.     // everything is OK    
  52.     public void start () {
  53.         if (initDone)
  54.             new DoQT();
  55.     }    
  56.     
  57.     class DoQT {
  58.         DoQT () {
  59.             try {                
  60.                 setLayout (new BorderLayout());
  61.                 
  62.                 QTCanvas myQTCanvas = new QTCanvas (QTCanvas.kInitialSize, 0.5F, 0.5F);
  63.                 add (myQTCanvas, "Center");    
  64.                 myQTCanvas.setClient (ImageDrawer.getQTLogo(), true);
  65.  
  66.                 add (new Label ("QuickTime for Java"), "North");
  67.                 add (new Label ("Installed successfully"), "South");
  68.             } catch (Throwable e) {
  69.                 if (e instanceof ClassNotFoundException) {
  70.                     add (new Label ("Can't Find QTJava classes"), "North");
  71.                     add (new Label ("Check install and try again"), "South");
  72.                 } else {
  73.                     System.out.println (e);
  74.                     e.printStackTrace();
  75.                 }
  76.             }        
  77.         }
  78.     }
  79.     
  80.     public void stop () {}
  81.     
  82.     public void destroy () {
  83.         if (initDone)
  84.             QTSession.close();
  85.         initDone = false;
  86.     }
  87. }
  88.